package com.mijie.homi.search.api;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mijie.homi.common.domain.SearchResult;
import com.mijie.homi.search.service.index.MoodUserIndexService;
import com.mijie.homi.search.service.index.UserIndexService;
import com.mijie.util.IOUtil;

@Controller
@RequestMapping("/user")
public class UserSearchApi {

	@Autowired
	private UserIndexService service;
	@Autowired
	private MoodUserIndexService moodUserService;
	
	private Logger logger = Logger.getLogger(this.getClass());
	
	@RequestMapping(value="/search",method=RequestMethod.GET)
	public  void search(String idxf,int offset,int limit,String keyword,HttpServletResponse response) throws Exception{
		SearchResult result = service.search(idxf, offset, limit, keyword);
		IOUtil.write(response, result.toJSON());
	}
	
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public @ResponseBody void RAMIndex(int userId,String nickName){
		service.RAMIndex(userId, nickName);
	}
	
	@RequestMapping(value="/match",method=RequestMethod.GET)
	public  void match(String idxf,int offset,int limit,int userId,int gender,HttpServletResponse response) throws Exception{
		SearchResult result = moodUserService.match(idxf, offset, limit, userId, gender);
		IOUtil.write(response, result.toJSON());
	}
}
